<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: PointCalculatorLoader</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.points</a> ]
    </div>

    <h1>Coverage Summary for Class: PointCalculatorLoader (nl.tudelft.jpacman.points)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">PointCalculatorLoader</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 5)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 17)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.points;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import java.io.IOException;
        <i>4</i>&nbsp;import java.net.URL;
        <i>5</i>&nbsp;import java.net.URLClassLoader;
        <i>6</i>&nbsp;import java.util.Properties;
        <i>7</i>&nbsp;
        <i>8</i>&nbsp;/**
        <i>9</i>&nbsp; * The responsibility of this loader is to obtain the appropriate points calculator.
        <i>10</i>&nbsp; * By default the {@link DefaultPointCalculator} is returned.
        <i>11</i>&nbsp; */
        <b class="nc"><i>12</i>&nbsp;public class PointCalculatorLoader {</b>
        <i>13</i>&nbsp;
        <b class="nc"><i>14</i>&nbsp; private static Class clazz = null;</b>
        <i>15</i>&nbsp;
        <i>16</i>&nbsp; /**
        <i>17</i>&nbsp; * Load a points calculator and return it.
        <i>18</i>&nbsp; *
        <i>19</i>&nbsp; * @return The (dynamically loaded) points calculator.
        <i>20</i>&nbsp; */
        <i>21</i>&nbsp; public PointCalculator load() {
        <i>22</i>&nbsp; try {
        <b class="nc"><i>23</i>&nbsp; if (clazz == null) {</b>
        <b class="nc"><i>24</i>&nbsp; clazz = loadClassFromFile();</b>
        <i>25</i>&nbsp; }
        <i>26</i>&nbsp;
        <b class="nc"><i>27</i>&nbsp; return (PointCalculator) clazz.newInstance();</b>
        <b class="nc"><i>28</i>&nbsp; } catch (Exception e) {</b>
        <b class="nc"><i>29</i>&nbsp; throw new RuntimeException(&quot;Could not dynamically load the points calculator.&quot;,
            e);</b>
        <i>30</i>&nbsp; }
        <i>31</i>&nbsp; }
        <i>32</i>&nbsp;
        <i>33</i>&nbsp; private Class loadClassFromFile() throws IOException, ClassNotFoundException {
        <b class="nc"><i>34</i>&nbsp; String strategyToLoad = getCalculatorClassName();</b>
        <i>35</i>&nbsp;
        <b class="nc"><i>36</i>&nbsp; if (&quot;DefaultPointCalculator&quot;.equals(strategyToLoad)) {</b>
        <b class="nc"><i>37</i>&nbsp; return DefaultPointCalculator.class;</b>
        <i>38</i>&nbsp; }
        <i>39</i>&nbsp;
        <b class="nc"><i>40</i>&nbsp; URL[] urls = new URL[]{getClass().getClassLoader().getResource(&quot;scoreplugins/&quot;)};</b>
        <i>41</i>&nbsp;
        <b class="nc"><i>42</i>&nbsp; try (URLClassLoader classLoader = new URLClassLoader(urls,
            getClass().getClassLoader())) {</b>
        <b class="nc"><i>43</i>&nbsp; return classLoader.loadClass(strategyToLoad);</b>
        <b class="nc"><i>44</i>&nbsp; }</b>
        <i>45</i>&nbsp; }
        <i>46</i>&nbsp;
        <i>47</i>&nbsp; private String getCalculatorClassName() throws IOException {
        <b class="nc"><i>48</i>&nbsp; Properties properties = new Properties();</b>
        <i>49</i>&nbsp;
        <b class="nc"><i>50</i>&nbsp; properties.load(getClass().getClassLoader().getResourceAsStream(&quot;scorecalc.properties&quot;));</b>
        <i>51</i>&nbsp;
        <b class="nc"><i>52</i>&nbsp; return properties.getProperty(&quot;scorecalculator.name&quot;);</b>
        <i>53</i>&nbsp; }
        <i>54</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
